package cn.signalpha.modules.base.service;

import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.base.entity.NoticeTemplate;
import cn.signalpha.modules.base.mapper.NoticeTemplateMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class NoticeTemplateService extends ServiceImpl<NoticeTemplateMapper, NoticeTemplate> {

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<NoticeTemplate> selectNoticeTemplateWrapper(Map<String, Object> params) {
        QueryWrapper<NoticeTemplate> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("type")), NoticeTemplate::getType, params.get("type"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("status")), NoticeTemplate::getStatus, params.get("status"));
        wrapper.lambda().orderByAsc(NoticeTemplate::getId);
        return wrapper;
    }

	/**
	 * 根据类型查询
	 */
    public NoticeTemplate getByType(String type) {
		return baseMapper.selectOne(Wrappers.<NoticeTemplate>lambdaQuery().eq(NoticeTemplate::getType, type));
    }
}

